package com.newtouch.bxzs.database.synchronize.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newtouch.bxzs.common.base.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 用户Mapper:
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/30 10:15</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface SystemUserMapper extends BaseMapper<User> {

    /**
     * 批量插入用户数据
     * @param systemUser 用户信息
     * @param createTime 创建时间
     * @return int
     */
    @Insert({"<script>insert into ASSISTANT_USER(USER_ID,USER_JOB_NUMBER,USER_NAME,USER_SEX," +
            "USER_PHONE,USER_TELEPHONE,USER_CERTIFICATE_TYPE,USER_CERTIFICATE_NUMBER," +
            "USER_ENTRY_TIME,USER_WORKING_STATUS,USER_ADDRESS,USER_LEADER_JOB_NUMBER,USER_DEPARTMENT_NAME," +
            "IS_ENABLE,USER_LOGIN_ACCOUNT_NUMBER,USER_LOGIN_PASSWORD,USER_INTRODUCTION," +
            "USER_EMAIL,IS_DELETE,USER_BIRTHDAY,USER_WECHAT_NUMBER,USER_ORGANIZATION_CODE," +
            "USER_ORGANIZATION_NAME,CREATE_USER_ID,CREATE_TIME) values" +
            "<foreach collection='list' item='item' separator=',' >"+
            "(REPLACE(uuid(),'-','')," +
            "#{item.userJobNumber},#{item.userName},#{item.userSex}," +
            "#{item.userPhone},#{item.userTelephone},#{item.userCertificateType},#{item.userCertificateNumber}," +
            "#{item.userEntryTime},#{item.userWorkingStatus}," +
            "#{item.userAddress},#{item.userLeaderJobNumber},#{item.userDepartmentName},1," +
            "#{item.userJobNumber},'123456',#{item.userIntroduction}," +
            "#{item.userEmail},0," +
            "#{item.userBirthday},#{item.userWechatNumber}," +
            "#{item.userOrganizationCode},#{item.userOrganizationName}," +
            "'admin',#{createTime})" +
            "</foreach>" +
            "ON DUPLICATE KEY UPDATE" +
            " UPDATE_USER_ID = values(CREATE_USER_ID)</script>"})
    int addSystemUser(@Param("list") List<User> systemUser,@Param("createTime") Date createTime);
}
